package com.legendframework.core.cmd;

import com.legendframework.core.cmd.paramer.converter.ParamerConverter;
import com.legendframework.core.AbstractLegendPlugin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CommandManagerStore {

    private final List<ParamerConverter> paramerConverters = new ArrayList<>();

    private Map<Class<? extends AbstractLegendPlugin>,CommandManager> managerPool = new HashMap<>();

    public List<ParamerConverter> getParamerConverters() {
        return paramerConverters;
    }

    public Map<Class<? extends AbstractLegendPlugin>, CommandManager> getManagerPool() {
        return managerPool;
    }

    public List<ICommand> getCommands(AbstractLegendPlugin plugin) {
        CommandManager commandManager = managerPool.get(plugin.getClass());
        if (commandManager == null) {
            return new ArrayList<>();
        }
        return new ArrayList<>(commandManager.getCommands());
    }

    /**
     * 添加参数转换器
     * @param paramerConverter
     */
    public void addParamerConverter(ParamerConverter paramerConverter){
        paramerConverters.add(paramerConverter);
    }


    /**
     * 注册指令
     * @param command
     */
    public void registerCommond(AbstractLegendPlugin plugin , ICommand command) {
        CommandManager commandManager = managerPool.get(plugin.getClass());
        if (commandManager == null) {
            commandManager = new CommandManager(plugin);
            managerPool.put(plugin.getClass(),commandManager);
        }
        commandManager.getCommands().add(command);
    }
}
